package com.wyg.blog.config;

import com.wyg.blog.interceptor.LimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:    配置拦截规则,暂时弃用,后期如果有必要则开启使用
 * @author: WYG
 * @time: 2021/2/4 21:44
 */

@Configuration
@Profile({"dev"})
@ConfigurationProperties(prefix = "interceptor.path")
public class InterceptorConfig implements WebMvcConfigurer {

    private LimitInterceptor limitInterceptor;
    private List<String> path = new ArrayList<>();

    public void setPath(List<String> path) {
        this.path = path;
    }

    // 使用set注入
    @Autowired
    public void setLimitInterceptor(LimitInterceptor limitInterceptor) {
        this.limitInterceptor = limitInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截特定的请求路径,拦截路径在application.yml配置文件中配置
        registry.addInterceptor(limitInterceptor).addPathPatterns(path);
    }
}
